﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Util.Model;
using YiSha.Entity;
using YiSha.Model;
using YiSha.Admin.Web.Controllers;
using YiSha.Entity.YiDongYuan;
using YiSha.Business.YiDongYuan;
using YiSha.Model.Param.YiDongYuan;
using YiSha.Web.Code;
using System.Drawing;
using System.IO;
using Microsoft.AspNetCore.Http;
using System.Text;

namespace YiSha.Admin.Web.Areas.YiDongYuan.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2021-06-07 10:00
    /// 描 述：数据导出控制器类
    /// </summary>
    [Area("YiDongYuan")]
    public class DetectionExportController : BaseController
    {
        private MechanicsApplyBLL mechanicsApplyBLL = new MechanicsApplyBLL();
        private DetectionExportBLL exportBLL = new DetectionExportBLL();

        #region 视图功能

        [AuthorizeFilter("yidongyuan:detectionexport:view")]
        public ActionResult DetectionExportIndex()
        {
            List<RegionReportEntity> regions = mechanicsApplyBLL.GetRegionListByDictType("Region").Result.Data;
            ViewBag.Region = regions;
            return View();
        }

        #endregion 视图功能

        [HttpPost]
        public async Task<IActionResult> ExportDetectionJson(ExportListParam param)
        {
            TData<string> obj = new TData<string>();
            //根据区域
            TData<List<DetectionExportEntity>> userObj = await exportBLL.GetExportList(param);

            if (userObj.Tag == 1)
            {
                string file = new ExcelHelper<DetectionExportEntity>().ExportToExcel("非道机械数据.xls",
                                                                          "非道机械数据",
                                                                          userObj.Data,
                                                                          new string[] { "环保号牌", "所有人",
                                                                              "电话", "所属县区", "机械类型","机械名称",
                                                                          "排放阶段","燃油类型","发动机功率","机械型号",
                                                                          "机械出厂日期","检测日期","检测人","检测类型","检测结果","低排区"});
                obj.Data = file;
                obj.Tag = 1;
            }
            return Json(obj);
        }
    }
}
